﻿<UserControl x:Class="Sautom.Modules.Client.Controls.OrderViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:res="clr-namespace:Sautom.I18N;assembly=Sautom.I18N" 
             xmlns:l="clr-namespace:Sautom.ClientComunication.Converters;assembly=Sautom.ClientComunication"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <l:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        <l:BoolToVisibilityInversedConverter x:Key="BoolToVisibilityInversedConverter" />

        <DataTemplate x:Key="ListBoxTemplateWithCheckBoxes">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <CheckBox IsChecked="{Binding IsSelected}" />
                <TextBlock Grid.Column="1" Text="{Binding Value}" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ListBoxTemplateWithDisabledCheckBoxes">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <CheckBox IsChecked="{Binding IsSelected}" IsEnabled="false" />
                <TextBlock Grid.Column="1" Text="{Binding Value}" />
            </Grid>
        </DataTemplate>

        <Style TargetType="Grid">            
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext}" Value="{x:Null}">
                    <Setter Property="Visibility" Value="Hidden" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid DataContext="{Binding Order}">
        <Grid.RowDefinitions>
            <RowDefinition Height="60*" />
            <RowDefinition Height="60*" />
            <RowDefinition Height="60*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="60*" />
            <ColumnDefinition Width="60*" />
        </Grid.ColumnDefinitions>
        <StackPanel>
            <Label Content="{Binding Source={x:Static res:ClientResources.SchoolNameLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding SchoolName}" Grid.ColumnSpan="2" />
            <Label Content="{Binding Source={x:Static res:ClientResources.CourseNameLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding CourseName}" Grid.ColumnSpan="2" />
            <Label Content="{Binding Source={x:Static res:ClientResources.StartDateLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding StartDate, StringFormat=d}" Grid.ColumnSpan="2" />
            <Label Content="{Binding Source={x:Static res:ClientResources.EndDateLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding EndDate, StringFormat=d}" Grid.ColumnSpan="2" />
        </StackPanel>

        <StackPanel Grid.Column="1">
            <Label Content="{Binding Source={x:Static res:ClientResources.IntensityLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding Intensity}" Grid.ColumnSpan="2" />
            <Label Content="{Binding Source={x:Static res:ClientResources.HouseTypeLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding HouseType}" Grid.ColumnSpan="2" />
            <Label Content="{Binding Source={x:Static res:ClientResources.ResponsibleManagerLabel}}" Grid.ColumnSpan="2" />
            <TextBlock Text="{Binding ResponsibleManager}" Grid.ColumnSpan="2" />
            <!--<Button Content="Изменить" HorizontalAlignment="Right" Width="100" Command="{Binding DataContext.EditOrderAdvancedCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}" />-->
        </StackPanel>

        <StackPanel Grid.Row="1" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibilityConverter}}" Grid.ColumnSpan="2">
            <Label Content="{Binding Source={x:Static res:ClientResources.EmbassyDateLabel}}" />
            <DatePicker SelectedDate="{Binding EmbassyDate, StringFormat=d}" DisplayDateEnd="{Binding VisaDate}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.VisaGetDateLabel}}" />
            <DatePicker SelectedDate="{Binding VisaDate, StringFormat=d}" DisplayDateStart="{Binding EmbassyDate}" />
            <DockPanel Margin="5,5,0,0">
                <CheckBox IsChecked="{Binding IsEmbassyChecked}" />
                <Label Content="{Binding Source={x:Static res:ClientResources.IsEmbassyCheckedLabel}}" Margin="5,0,0,0" />
            </DockPanel>
            <Label Content="{Binding Source={x:Static res:ClientResources.EmbasyDocsLabel}}" />
            <ListBox DataContext="{Binding 
                            RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}" 
                                 ItemsSource="{Binding EmbasyDocs}" ItemTemplate="{StaticResource ListBoxTemplateWithCheckBoxes}" MaxHeight="100" />
            <Button Height="20" Width="250" HorizontalAlignment="Left" Content="{Binding Source={x:Static res:ClientResources.OrderInfoToPrintBtn}}" 
                    Command="{Binding DataContext.PrintOrderDetails, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
                    CommandParameter="{Binding Id}" />
        </StackPanel>

        <StackPanel Grid.Row="1" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibilityInversedConverter}}" Grid.ColumnSpan="2">
            <Label Content="{Binding Source={x:Static res:ClientResources.EmbassyDateLabel}}" />
            <TextBlock Text="{Binding EmbassyDate, StringFormat=d}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.VisaGetDateLabel}}" />
            <TextBlock Text="{Binding VisaDate, StringFormat=d}" />
            <DockPanel Margin="5,5,0,0">
                <CheckBox IsChecked="{Binding IsEmbassyChecked}" IsEnabled="false" />
                <Label Content="{Binding Source={x:Static res:ClientResources.IsEmbassyCheckedLabel}}" Margin="5,0,0,0" />
            </DockPanel>
            <Label Content="{Binding Source={x:Static res:ClientResources.EmbasyDocsLabel}}" />
            <ListBox DataContext="{Binding 
                            RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}" 
                                 ItemsSource="{Binding EmbasyDocs}" ItemTemplate="{StaticResource ListBoxTemplateWithDisabledCheckBoxes}" MaxHeight="100" />
            <Button Height="20" Width="250" HorizontalAlignment="Left" Content="{Binding Source={x:Static res:ClientResources.OrderInfoToPrintBtn}}" Command="{Binding DataContext.PrintOrderDetails, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
        </StackPanel>

        <StackPanel Margin="0,10,0,0" Grid.Row="2" Grid.Column="0" DataContext="{Binding AirlineTicket}" 
                                Visibility="{Binding DataContext.IsShowAirlineTicket, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}, 
                                Converter={StaticResource BoolToVisibilityConverter}}">
            <Label Content="{Binding Source={x:Static res:ClientResources.DepartureDateLabel}}" />
            <TextBlock Text="{Binding DepartureDate, StringFormat=d}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.DepartureCityLabel}}" />
            <TextBlock Text="{Binding DepartureCity}" />

            <Label Content="{Binding Source={x:Static res:ClientResources.ArrivalDateLabel}}" />
            <TextBlock Text="{Binding ArrivalDate, StringFormat=d}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.ArrivalCityLabel}}" />
            <TextBlock Text="{Binding ArrivalCity}" />
        </StackPanel>
        <StackPanel Margin="0,10,0,0" Grid.Row="2" Grid.Column="1" DataContext="{Binding AirlineTicket}" 
                                Visibility="{Binding DataContext.IsShowAirlineTicket, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}, 
                                Converter={StaticResource BoolToVisibilityConverter}}">
            <Label Content="{Binding Source={x:Static res:ClientResources.BookingDateLabel}}" />
            <TextBlock Text="{Binding BookingDate, StringFormat=d}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.BookingExpireDateLabel}}" />
            <TextBlock Text="{Binding BookingExpireDate, StringFormat=d}" />
            <Label Content="{Binding Source={x:Static res:ClientResources.RedemptionDateLabel}}" />
            <TextBlock Text="{Binding RedemptionDate, StringFormat=d}" />
        </StackPanel>
    </Grid>
</UserControl>
